<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增核算单位')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-hsdw-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">上级单位编码：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="sjdwbm" type="hidden" th:value="${tGgHsdw?.dwbm}"/>
                        <input class="form-control" type="text" onclick="selectHsdwTree()" id="treeName" readonly="true" th:value="${tGgHsdw?.dwmc}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">单位编码：</label>
                <div class="col-sm-8">
                    <input name="dwbm" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">单位名称：</label>
                <div class="col-sm-8">
                    <input name="dwmc" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">单位地址：</label>
                <div class="col-sm-8">
                    <input name="dwdz" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">单位负责人：</label>
                <div class="col-sm-8">
                    <input name="dwlxr" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">单位联系电话：</label>
                <div class="col-sm-8">
                    <input name="dwlxdh" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否末级：</label>
                <div class="col-sm-8">
                     <select name="sfmj" class="form-control">
					     <option value="0">否</option>
						 <option value="1">是</option>
					 </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">级次：</label>
                <div class="col-sm-8">
                    <input name="jc" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">经办人：</label>
                <div class="col-sm-8">
                    <input name="jbr" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">经办时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="jbsj" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="bz" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">单位账号：</label>
                <div class="col-sm-8">
                    <input name="dwzh" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">单位银行名称：</label>
                <div class="col-sm-8">
                    <input name="dwyh" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">部门编码：</label>
                <div class="col-sm-8">
                    <input name="bmbm" class="form-control" type="text">
                </div>
            </div>
           
            <div class="form-group">    
                <label class="col-sm-3 control-label">核算中心账户名称：</label>
                <div class="col-sm-8">
                    <input name="hszhmc" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">核算中心开户行：</label>
                <div class="col-sm-8">
                    <input name="hskhh" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">核算中心账号：</label>
                <div class="col-sm-8">
                    <input name="hszh" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/hsdw"
        $("#form-hsdw-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
            	var sjdwbm=$("input[name='sjdwbm']").val();
            	var dwbm=$("input[name='dwbm']").val();
            	var jc=$("input[name='jc']").val();
            	if(!$.common.numValid(dwbm)){
        			$.modal.alertWarning("单位编码只能为数字");
        			return false;
        		}
            	if (sjdwbm!=''){
            		if (dwbm.substring(0,sjdwbm.length)!=sjdwbm){
            			$.modal.alertWarning("单位编码必须包含上级单位编码");
            			return false;
            		}
            	}
            	if(!$.common.numValid(jc)){
        			$.modal.alertWarning("单位级次只能为数字");
        			return false;
        		}
            	var dwLen=Number(jc)*2+1;
            	if (dwbm.length!=dwLen){
        			$.modal.alertWarning("单位编码长度不对");
        			return false;
        		}
                $.operate.save(prefix + "/add", $('#form-hsdw-add').serialize());
            }
        }

        $("input[name='jbsj']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        /*核算单位-新增-选择父部门树*/
        function selectHsdwTree() {
            var options = {
                title: '核算单位选择',
                width: "380",
                url: prefix + "/selectHsdwTree/" + $("#treeId").val(),
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
               $("#treeId").val(body.find('#treeId').val());
               $("#treeName").val(body.find('#treeName').val());
               layer.close(index);
        }
    </script>
</body>
</html>